package net.sourceforge.m2settings;

import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;

import net.sourceforge.m2settings.model.Settings;

import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.InputSource;

public class XMLBinder {
	public String toXML(Object obj) throws IOException, MarshalException, ValidationException {
		StringWriter w = new StringWriter();
		Marshaller marshaller = new Marshaller(w);
		marshaller.marshal(obj);
		return w.toString();
	}

	public Settings loadSettings(InputSource xmlSettingsIS) throws MarshalException, ValidationException {
		Unmarshaller um=new Unmarshaller(Settings.class);
		return (Settings) um.unmarshal(xmlSettingsIS);
	}
	public Settings loadSettings(Reader xmlSettingsReader) throws MarshalException, ValidationException {
		Unmarshaller um=new Unmarshaller(Settings.class);
		return (Settings) um.unmarshal(xmlSettingsReader);
	}
}
